﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class ExportExcel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {


        Response.Clear();

        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("content-disposition", "attachment;filename=MyFiles.xls");
        Response.ContentEncoding = System.Text.Encoding.Unicode;
        Response.ContentType = "application/vnd.ms-excel";

        Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
       // Response.Charset = System.Text.Encoding.Unicode.WebName;
        Response.Write(GenHtmlTable());
        Response.End();
    }
    public object GenHtmlTable()
    {
        object sRet = null;

        sRet = sRet + "<table border=1 class=mysmalltext>";
        sRet = sRet + "<tr><td colspan=2 align=\"center\" style=\"background-color:Blue; font-size:large;\">";
        sRet = sRet + "        NGUYỄN THÁI THỊNH</td></tr>";
        sRet = sRet + "<tr bgcolor=\"#d8ecea\">";
        sRet = sRet + "<td>Name</td>";
        sRet = sRet + "<td>Country</td>";
        sRet = sRet + "</tr>";

        //Beginning rows...Might read from Recordset - here it's hardcoded
        sRet = sRet + "<tr>";
        sRet = sRet + "<td>John Doe</td>";
        sRet = sRet + "<td>US</td>";
        sRet = sRet + "</tr>";

        sRet = sRet + "<tr>";
        sRet = sRet + "<td>Stefan Holmberg</td>";
        sRet = sRet + "<td>Sweden</td>";
        sRet = sRet + "</tr>";

        sRet = sRet + "<tr>";
        sRet = sRet + "<td>";
        sRet = sRet + "<img src=\"http://localhost/imarkets/Css/skin/ired/mods.core/img.bg/mods.core.png\" width=\"200\" height=\"200\"/></td>";
        sRet = sRet + "<td>&nbsp;</td></tr>";
        sRet = sRet + "</table>";
        return sRet;
    }
}
